package main

// 对一个公司几万员工的年龄排序

func SortAges(ages []int, min, max int) {
	if len(ages) == 0 {
		return
	}
	var youngAge = min  // 最小年龄
	var oldestAge = max // 最大年龄
	var timesOfAge = make([]int, max+1)

	for i := 0; i < len(ages); i++ {
		var age = ages[i]
		if age < youngAge || age > oldestAge {
			panic("age out of range")
		}
		timesOfAge[age]++
	}

	var index = 0
	for i := 0; i <= oldestAge; i++ {
		for j := 0; j < timesOfAge[i]; j++ {
			ages[index] = i
			index++
		}
	}
}
